﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cludg.Repository.NHibernate.Extensions
{
	public class NHMappingExtensionRegistry : INHMappingExtensionRegistry
	{
		protected readonly List<INHMappingExtension> Extensions = new List<INHMappingExtension>();
		protected readonly List<INHMappingExtensionProvider> Providers = new List<INHMappingExtensionProvider>();

		public NHMappingExtensionRegistry(IEnumerable<INHMappingExtensionProvider> providers)
		{
			foreach (var provider in providers)
			{
				RegisterProvider(provider);
			}
		}

		protected void RegisterProvider(INHMappingExtensionProvider provider)
		{
			Providers.Add(provider);
			foreach (var extension in provider.GetExtesions())
			{
				Register(extension);
			}
		}

		public void Register(INHMappingExtension extension)
		{
			Extensions.Add(extension);
		}

		public IEnumerable<INHMappingExtension> Get()
		{
			return Extensions;
		}
	}
}
